package com.ksl.kinglockguard.widget;

import org.egret.egretframeworknative.engine.IGameZipUpdateListener;

import android.content.Context;
import android.os.Handler;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import com.ksl.kinglockguard.activity.GamePlayActivity;
import com.lsk.open.core.MyLog;

public class GameLoadingView extends FrameLayout implements IGameZipUpdateListener{


    private ProgressBar bar;
    private Handler mHandler;
    
    public GameLoadingView(Context context) {
        super(context);
        bar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
        this.addView(bar);
    }
    
    public GameLoadingView(Context context, Handler handler) {
        super(context);
        mHandler = handler;
        bar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
        this.addView(bar);
    }

    @Override
    public void onGameZipUpdateError() {
    	if(mHandler != null) {
    		mHandler.sendEmptyMessage(GamePlayActivity.MSG_WHAT_SHOW_TIPS);
    	}
    }

    @Override
    public void onGameZipUpdateProgress(float arg0) {
        bar.setProgress((int) arg0);
    }

    @Override
    public void onGameZipUpdateSuccess() {
    	if(mHandler != null) {
    		mHandler.sendEmptyMessage(GamePlayActivity.MSG_WHAT_STOP_LOADING);
    	}
        MyLog.d("GamePlayA", "success");
    }
}
